using System;
using System.Linq;
using NUnit.Framework;

namespace Solver
{
	/// <summary>
	/// What is the smallest number divisible by each of the numbers 1 to 20?
	/// </summary>
	public class Problem005 : SelfChecker, IProblem
	{
		public int Id
		{
			get { return 5; }
		}

		public string Solve()
		{
			return Solve(20).ToString();
		}

		[Test]
		public override void Check()
		{
			Assert.AreEqual(2520, Solve(10));
			Assert.AreEqual(232792560, Solve(20));
		}

		private static int Solve(int param)
		{
			return new EratosthenesSieve(param).Primes()
				.Aggregate(1, (total, p) => total * Convert.ToInt32(Math.Pow(p, Math.Floor(Math.Log(param, p)))));
		}
	}
}